package com.qing.design.patterns.mediator.example.components;

import com.qing.design.patterns.mediator.example.mediator.Mediator;
import com.qing.design.patterns.mediator.example.mediator.Note;

import javax.swing.*;
import java.awt.event.ActionEvent;

/**
 * 构件之间不会相互交谈。他们只有一个
 * 通信通道–向中介发送请求。
 */
public class AddButton  extends JButton implements Component{


	private Mediator mediator;

	public AddButton() {
		super("Add");
	}

	@Override
	public void setMediator(Mediator mediator) {
		this.mediator=mediator;
	}

	@Override
	protected void fireActionPerformed(ActionEvent event) {
		mediator.addNewNote(new Note());
	}

	public String getName(){
		return  "AddButton";
	}
}
